package com.api.shopapi.service.impl;


import com.api.shopapi.entity.Article;
import com.api.shopapi.entity.dto.ArticleDTO;
import com.api.shopapi.mapper.ArticleMapper;
import com.api.shopapi.service.ArticleService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("ArticleServiceImplOne")
public class ArticleServiceImpl implements ArticleService {
    @Autowired
    private ArticleMapper articleMapper;

    @Override
    public int insert(Article article) {
        return articleMapper.insert(article);
    }

    @Override
    public int update(Article article) {
        return articleMapper.update(article);
    }

    @Override
    public Article getByArticleCode(String articleCode) {
        return articleMapper.getByArticleCode(articleCode);
    }

    @Override
    public PageInfo<ArticleDTO> getPageList(int pageIndex, int pageSize, String governmentCode, String title,
                                            int status, String startTime, String endTime, String communityCode, String networkCode) {
        PageHelper.startPage(pageIndex,pageSize);
        List<ArticleDTO> articleList =articleMapper.getPageList(governmentCode,title,status,startTime,endTime,communityCode,networkCode);
        return new PageInfo<>(articleList);
    }

    @Override
    public
    PageInfo<ArticleDTO> pageByGovCode(int pageIndex, int pageSize, String governmentCode){
        PageHelper.startPage(pageIndex,pageSize);
        List<ArticleDTO> articleList =articleMapper.listByGovCode(governmentCode);
        return new PageInfo<>(articleList);
    }

}
